package 剑指offer;

/**
 * Created by lenovo】 on 2017/3/21.
 */
public class NumberOf1Between1AndN_Solution {
    public int NumberOf1Between1AndN_Solution(int n) {

        int numOf1 = 0;
        for (int i = 1; i <= n; i++) {
            String s = String.valueOf(i);
            char [] charArray = s.toCharArray();
            int lenOfchar = charArray.length;
            for (int j = 0; j < lenOfchar; j++) {
                if (charArray[j] == '1') {
                    numOf1 ++;
                }
            }
        }
        return numOf1;
    }
}
